from apps.common.base.serializers import *
from apps.system.article.models import *


class ArticleBaseSerializer(BaseSerializer):
    class Meta:
        model = Article
        fields = "__all__"


class ArticleModelSerializer(BaseSerializer):

    cateModel = serializers.SerializerMethodField()
    def get_cateModel(self, obj):
        try:
            return {'id': obj.cate.id, 'label': obj.cate.label}
        except:
            return {}

    readUserCount = serializers.SerializerMethodField()
    def get_readUserCount(self, obj):
        try:
            return obj.users.count()
        except:
            return 0

    class Meta:
        model = Article
        fields = "__all__"
